package com.asia5b.a5mall.middleware.logic.viewmodel.order

import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.R
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.order.OrderAfterSaleDetailModel
import com.asia5b.a5mall.middleware.utils.showMessage
import io.reactivex.functions.Consumer

/**
 * Created by zhangyuncai on 2020/1/13.
 */
class OrderAfterSaleActivityVM:SimpleViewModel() {

    /**
     * @Note   加载售后数据
     * @param  orderSn   订单号
     * @param  skuId     单个商品时的SkuId
     * //http://47.88.223.5:4001/after-sales/refunds/cancel-order
    /*
    order_sn: 20200113000006
    return_money: 1,896.00
    refund_reason: 买错/不想要
    customer_remark: 不好用
    */
     */
    fun getOrderAftersaleDetail(orderSn: String, skuId: Int) {
        val map = HashMap<String, Any>()
        if (skuId > 0) {
            map.put("sku_id", skuId)
        }
        val observable = afterSaleApi.getRefundData(orderSn, map)
        baseSubscribe(observable, Consumer { result ->
//            providerView().getOrderAftersaleDetailResult(result)
            getOrderAftersaleDetailResultLiveData.value=result
        })
    }
    val getOrderAftersaleDetailResultLiveData= MutableLiveData<OrderAfterSaleDetailModel>()
    /**
     * @Note   退款
     *
     *      /*
    http://47.88.223.5:4001/after-sales/return-goods/apply
    account_type:
    order_sn: 20200111000011
    return_num: 1
    return_money: 440.00
    refund_reason: 不喜欢/不想要
    customer_remark: 1234
    sku_id: 25256
    */
     */
    fun commitMoney(map: HashMap<String, Any>) {
        val observable = afterSaleApi.applyRefunds(map)
        baseSubscribe(observable, Consumer {
            showMessage(R.string.退款成功)
//            providerView().commitMoneyResult()
            commitMoneyResultLiveData.value=true
        })
    }
    val commitMoneyResultLiveData= MutableLiveData<Boolean>()
    /**
     * @Note   退货
     * @param  returnData  参数
     */
    fun commitGoods(map: HashMap<String, Any>) {
        val observable = afterSaleApi.applyReturnGoods(map)
        baseSubscribe(observable, Consumer {
            showMessage(R.string.退货成功)
//            providerView().commitGoodsResult()
            commitGoodsResultLiveData.value=true
        })
    }
    val commitGoodsResultLiveData= MutableLiveData<Boolean>()
    /**
     * @Note   确认收货前的退款
     * @param  returnData  参数
     */
    fun cancelPaidOrder(map: HashMap<String, Any>) {
        val observable = afterSaleApi.cancelPaidOrder(map)
        baseSubscribe(observable, Consumer {
            showMessage(R.string.取消成功)
//            providerView().commitGoodsResult()
            commitGoodsResultLiveData.value=true
        })
    }
}